<?php
class cct_order extends ctl_order{

    var $noCache = true;

	function create(){
        $this->begin($this->system->mkUrl('cart', 'checkout'));
        $this->_verifyMember(false);
        $order = $this->system->loadModel('trading/order');
        $oCart = $this->system->loadModel('trading/cart');
        $oCart->checkMember($this->member);
        $cart = $oCart->getCart('all');
		//alone start
				if(!$_POST["99bill_period"]) {
					 $_POST["99bill_period"] = $_POST["icbc_period"];
				}
        $orderid = $order->create($cart, $this->member,$_POST['delivery'],$_POST['payment'],$_POST['minfo'],$_POST["99bill_bank"],$_POST["99bill_period"]);
		//alone end
        if($orderid){
            if($_POST['fromCart']){
                $oCart->clearAll();
            }
/*             $this->redirect('index','order',array($orderid)); */
        }else{
            trigger_error('对不起，订单创建过程中发生问题，请重新提交或稍后提交',E_USER_ERROR);
        }
				//alone start
				$oPro = $this->system->loadModel('goods/products');
				$oPro->addSellLog(array('order_id'=>$orderid));
				//error_log(var_export($oPro,true),3,__FILE__.".log");
				//alone end
        $this->system->setcookie('ST_ShopEx-Order-Buy', md5($this->system->getConf('certificate.token').$orderid));

         $this->end_only(true, '订单建立成功', $this->system->mkUrl('order', 'index', array($orderid)));
        $this->redirect('order','index',array($orderid));
    }

    function index($order_id, $selecttype=false){
	//	array(var_export($POST['banklist'],true),3,__FILE__.".1.log");
        if($_COOKIE['ST_ShopEx-Order-Buy'] != md5($this->system->getConf('certificate.token').$order_id)){
            $this->splash('failed','index.php',__('订单无效！'));
        }
        $this->_verifyMember(false);
        $objOrder = $this->system->loadModel('trading/order');
        $aOrder = $objOrder->load($order_id);
        $aOrder['cur_money'] = ($aOrder['amount']['total'] - $aOrder['amount']['payed']) * $aOrder['cur_rate'];
        $this->pagedata['order'] = $aOrder;
        if(!$this->pagedata['order']){
            $this->system->error(404);
            exit;
        }

        if($selecttype){
            $selecttype = 1;
//            $shipping = $this->system->loadModel('trading/delivery');
//            $this->pagedata['delivery'] = $shipping->checkDlTypePay($this->pagedata['order']['shipping']['id'], $this->pagedata['order']['shipping']['area']);
            $payment = $this->system->loadModel('trading/payment');
            $this->pagedata['payments'] = $payment->getByCur($this->pagedata['order']['currency']);
        }else{
            $selecttype = 0;
        }
        $this->pagedata['order']['selecttype'] = $selecttype;
		//alone 去掉下面的
		//$this->pagedata['order']['paytype'] = strtoupper($this->pagedata['order']['paytype']);
        $objCur = $this->system->loadModel('system/cur');
        $aCur = $objCur->getDefault();
        $this->pagedata['order']['cur_def'] = $aCur['cur_code'];

        $this->output();
    }

}
?>